package com.lsh.payment.core.util.pay.icp;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;


public class MessageUtil {
    public static String getSignStr(String body) {
        JSONObject jsonObject = JSON.parseObject(body);
        Set<Map.Entry<String, Object>> entries = jsonObject.entrySet();
        TreeMap<String, Object> map = new TreeMap<>();
        for (Map.Entry<String, Object> entry : entries) {
            map.put(entry.getKey(), entry.getValue());
        }
        if (map.size() == 0) {
            //
            map.put("emptybody","emptybodysignvalue");
        }
        StringBuffer buf = new StringBuffer();
        for (String key : map.keySet()) {
            buf.append(key).append("=").append((String) map.get(key)).append("&");
        }
        return buf.toString();
    }
}
